package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.SelectBelongsBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

/**
 * 选择所属项目adapter
 * <p>
 * Created by Administrator on 2017/8/31.
 */

public class ProjectSelectAdapter extends BaseRecyclerViewAdapter<SelectBelongsBean.Rows> {


    private String contractId;

    public ProjectSelectAdapter(Context context, String contractId) {
        super(context);
        this.contractId = contractId;
    }

    @Override
    public SelectBelongsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_select_belongs, null);
        return new SelectBelongsViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        SelectBelongsViewHolder holder = (SelectBelongsViewHolder) rholder;

        final SelectBelongsBean.Rows rows = mList.get(position);
        //1：已生效 2：已到期 3：缓存期
        if ("1".equals(rows.getContractFlag())) {
            holder.tvTitle.setText(rows.getContractName() + "(已生效)");
        } else if ("2".equals(rows.getContractFlag())) {
            holder.tvTitle.setText(rows.getContractName() + "(已到期)");
        } else if ("3".equals(rows.getContractFlag())) {
            holder.tvTitle.setText(rows.getContractName() + "(缓冲期)");
        }else if ("0".equals(rows.getContractFlag())){
            holder.tvTitle.setText(rows.getContractName() + "(待生效)");
        }else if ("4".equals(rows.getContractFlag())){
            holder.tvTitle.setText(rows.getContractName() + "(已关闭)");
        }else{
            holder.tvTitle.setText(rows.getContractName());
        }
        if (!TextUtils.isEmpty(contractId) && contractId.equals(rows.getContractId()+"")) {
            //选中
            holder.rlRoot.setBackgroundColor(Color.parseColor("#F5F9FF"));
        } else {
            holder.rlRoot.setBackgroundColor(Color.WHITE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mOnItemClickLitener.onItemClick(view, position);
            }
        });
    }

    static class SelectBelongsViewHolder extends RecyclerView.ViewHolder {
        private View itemView;
        private TextView tvTitle;//标题
        private RelativeLayout rlRoot;

        public SelectBelongsViewHolder(View view) {
            super(view);
            itemView = view;
            tvTitle = itemView.findViewById(R.id.tv_title);
            rlRoot = itemView.findViewById(R.id.rl_root);
        }
    }

}
